package com.zh.common;

import cn.hutool.core.util.StrUtil;
import com.zh.constant.CommonConstant;
import lombok.Data;

/**
 * 分页请求
 *
 * @author <a href="https://github.com/liyupi">程序员鱼皮</a>
 * @from <a href="https://yupi.icu">编程导航知识星球</a>
 */
@Data
public class PageRequest {

    /**
     * 当前页号
     */
    private Integer current = 1;

    /**
     * 页面大小
     */
    private Integer pageSize = 10;

    /**
     * 排序字段
     */
    private String sortField;

    /**
     * 排序顺序（默认升序）
     */
    private String sortOrder = CommonConstant.SORT_ORDER_DESC;

    public void standardizeSize() {
        if (this.current < 1) {
            this.current = 1;
        }
        if (this.pageSize < 1) {
            this.pageSize = 10;
        }
        if (StrUtil.isEmpty(sortField)) {
            sortField = "update_at";
        }
        if (StrUtil.isEmpty(sortOrder)) {
            sortOrder = CommonConstant.SORT_ORDER_DESC;
        }
    }
}
